import { reqCategoryList, reqGetBannerList, reqFloorList } from '../../api/index.js'
//home小仓库
const state = {
        // state初始值
        categoryList: [],
        bannerList: [],
        floorList: [],
    }
    //修改state的唯一手段
const mutations = {
        CATEGORYLIST(state, categoryList) {
            state.categoryList = categoryList;
        },
        GETBANNERLIST(state, bannerList) {
            state.bannerList = bannerList;
        },
        GETFLOORLIST(state, floorList) {
            state.floorList = floorList
        }
    }
    //处理action 可以书写自己的业务逻辑 也可以处理异步
const actions = {
    //通过API里面的接口函数调用，像服务器发请求，获取服务器的数据
    async categoryList(context) {
        let result = await reqCategoryList();
        if (result.code == 200) {
            context.commit('CATEGORYLIST', result.data);
        }

    },
    //获取首页轮播图的数据
    async getBannerList(context) {
        let result = await reqGetBannerList();
        if (result.code == 200) {
            context.commit('GETBANNERLIST', result.data);
        }
    },
    //获取floor数据
    async getFloorList(context) {
        let result = await reqFloorList();
        if (result.code == 200) {
            context.commit('GETFLOORLIST', result.data)
        }
    }
}
const getters = {}
export default {
    state,
    mutations,
    actions,
    getters,
}